import { createWebHistory, createRouter } from 'vue-router';
import routes from './routes';
import { isLogin } from '@/utils/util';
const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from) => {
  if (to.name !== 'login') {
    //判断是否已经登录
    if (localStorage.getItem('login') !== 'true') {
      return {
        name: 'login',
      };
    }
  }
  if (to.name === 'login') {
    if (localStorage.getItem('login') === 'true') {
      return {
        name: 'manage',
      };
    }
  }
  return true;
});

export default router;
